package com.df.my_net_game.game_rpc.utils;

import com.df.my_net_game.game_rpc.types.ByteWrapper;
import com.df.my_net_game.game_rpc.types.IntWrapper;
import com.df.my_net_game.game_rpc.types.LongWrapper;
import com.df.my_net_game.game_rpc.types.ShortWrapper;
import io.netty.util.concurrent.Promise;

public class TypeUtils {
    public static boolean isBaseType(Class<?> type) {
        if(type.equals(Promise.class)){
//            ty
        }
        return type.isPrimitive();
    }

    public static Object getWrapperParam(Class<?> parameterWrapperType, Object arg) {
        if(parameterWrapperType.equals(ByteWrapper.class)){
            ByteWrapper wrapper = new ByteWrapper();
            wrapper.setValue((Byte) arg);
            return wrapper;
        }
        if(parameterWrapperType.equals(ShortWrapper.class)){
            ShortWrapper wrapper = new ShortWrapper();
            wrapper.setValue((Short) arg);
            return wrapper;
        }
        if(parameterWrapperType.equals(IntWrapper.class)){
            IntWrapper wrapper = new IntWrapper();
            wrapper.setValue((Integer) arg);
            return wrapper;
        }
        if(parameterWrapperType.equals(LongWrapper.class)){
            LongWrapper wrapper = new LongWrapper();
            wrapper.setValue((Long) arg);
            return wrapper;
        }

        throw new RuntimeException("未支持的包装类型："+parameterWrapperType);
    }
}
